package com.sanjiahantang.youjiarole.module.goods.models.impl;

import android.content.Context;

import com.sanjiahantang.youjiarole.base.BaseBean;
import com.sanjiahantang.youjiarole.base.CallBack;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.http.BaseDelegate;
import com.sanjiahantang.youjiarole.http.OkHttpClientManager;
import com.sanjiahantang.youjiarole.module.cases.beans.DesignerBean;
import com.sanjiahantang.youjiarole.module.common.beans.CartGoodsBean;
import com.sanjiahantang.youjiarole.module.common.beans.StringBean;
import com.sanjiahantang.youjiarole.module.evaluate.beans.EvaServiceBean;
import com.sanjiahantang.youjiarole.module.goods.beans.CartNum;
import com.sanjiahantang.youjiarole.module.goods.beans.GoodsAttrBean;
import com.sanjiahantang.youjiarole.module.goods.beans.GoodsBean;
import com.sanjiahantang.youjiarole.module.goods.beans.GoodsListBean;
import com.sanjiahantang.youjiarole.module.goods.beans.GoodsSelectorBean;
import com.sanjiahantang.youjiarole.module.goods.models.IGoodsModel;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by zy on 2017/9/5.
 */

public class GoodsModel implements IGoodsModel {

    @Override
    public void loadFavoriteList(final Context context,Map<String,Object> param, final CallBack<GoodsListBean> callBack) {

        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/collect/phone/role/searchCollectForGoodsInfo",
                param,new BaseDelegate.ResultCallback<GoodsListBean>() {

                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(GoodsListBean response, Object tag) {
                        callBack.onSuccess(response,context, tag);
                    }
                });
    }

    @Override
    public void alterCartGoodsNumber(final Context context, Map<String, Object> params, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/shopping/phone/updateShoppingCartInfoForRole",
                params,new BaseDelegate.ResultCallback<GoodsListBean>() {

                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(GoodsListBean response, Object tag) {
                        callBack.onSuccess(response,context, tag);
                    }
                });
    }
   //查询购物车
    @Override
    public void getCartGoodsData(final Context context, Map<String, Object> params, final CallBack<CartGoodsBean> callBack) {

        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/shopping/phone/findShoppingCartInfoForRole",
                params,new BaseDelegate.ResultCallback<CartGoodsBean>() {

                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(CartGoodsBean response, Object tag) {
                        callBack.onSuccess(response,context, tag);
                    }
                });
    }
   //删除购物车
    @Override
    public void deleteCartGoods(final Context context, Map<String, Object> params, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/shopping/phone/deleteShoppingCartInfoForRole",
                params,new BaseDelegate.ResultCallback<GoodsBean>() {

                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(GoodsBean response, Object tag) {
                        callBack.onSuccess(response,context, tag);
                    }
                });
    }

    @Override
    public void getGoodDetail(final Context context, Map<String, Object> param, final CallBack<GoodsBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/goods/phone/searchGoodsInfoDetailForRole",
                param,new BaseDelegate.ResultCallback<GoodsBean>() {

                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(GoodsBean response, Object tag) {
                        callBack.onSuccess(response,context, tag);
                    }
                });
    }

    @Override
    public void resetGoodsList(final Context context, Map<String, Object> params, final CallBack<GoodsListBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/phone/goodsPage/searchMallGoodsInfoForPageForRole",
                params,new BaseDelegate.ResultCallback<GoodsListBean>() {

                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(GoodsListBean response, Object tag) {
                        callBack.onSuccess(response,context, tag);
                    }
                });
    }

    @Override
    public void getMoreList(final Context context, Map<String, String> params, final CallBack<GoodsListBean> callBack) {

    }

    @Override
    public void searchDesignAllAppraisePhone(final Context context, Map<String, Object> param, final CallBack<EvaServiceBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/phone/serviceAppraiseInfo/searchDesignAllAppraiseForRole",
                param,new BaseDelegate.ResultCallback<EvaServiceBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(EvaServiceBean response, Object tag) {
                callBack.onSuccess(response,context, tag);
            }
        });
    }
   //添加手长
    @Override
    public void addCollectInfo(final Context context, Map<String, Object> param, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/collect/phone/role/addCollectInfo",param,new BaseDelegate.ResultCallback<DesignerBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(DesignerBean response, Object tag) {
                callBack.onSuccess(response,context, tag);
            }
        });
    }

    @Override
    public void loadSelectors(final Context context, Map<String,String> param,final CallBack<GoodsSelectorBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/mall/phone/goodsPage/indexGoodsList",param,new BaseDelegate.ResultCallback<GoodsSelectorBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(GoodsSelectorBean response, Object tag) {
                callBack.onSuccess(response,context, tag);
            }
        });
    }

    @Override
    public void loadGoodsAttr(final Context context, Map<String, String> param, final CallBack<GoodsAttrBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/mall/goods/phone/searchMallBuyDetailForRole",param,new BaseDelegate.ResultCallback<GoodsAttrBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(GoodsAttrBean response, Object tag) {
                callBack.onSuccess(response,context, tag);
            }
        });
    }
  // 添加购物车
    @Override
    public void addShoppingCartInfoForCustomer(final Context context, Map<String, Object> param, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/shopping/phone/addShoppingCartInfoForRole",param,new BaseDelegate.ResultCallback<BaseBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(BaseBean response, Object tag) {
                callBack.onSuccess(response,context, tag);
            }
        });
    }
    //删除收藏
    @Override
    public void deleteCollectInfo(final Context context, Map<String, Object> param, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/collect/phone/role/deleteCollectInfo",param,new BaseDelegate.ResultCallback<DesignerBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(DesignerBean response, Object tag) {
                callBack.onSuccess(response,context, tag);
            }
        });
    }

    @Override
    public void getCartNum(final Context context, Map<String, Object> param, final CallBack<CartNum> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/mall/shopping/phone/findShoppingCartNumberForRole",param,new BaseDelegate.ResultCallback<CartNum>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(CartNum response, Object tag) {
                callBack.onSuccess(response,context, tag);
            }
        });
    }

    @Override
    public void findGoodsSpecifionsDetailInfo(final Context context, Map<String, String> map, final CallBack<StringBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/mall/goods/pecifications/findGoodsSpecifionsDetailInfo",map,new BaseDelegate.ResultCallback<StringBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(StringBean response, Object tag) {
                callBack.onSuccess(response,context, tag);
            }
        });
    }
}
